const jwt = require('jsonwebtoken')
const {
	KEY
} = require('../config/token')
module.exports = (req, res, next) => {
	const token = req.get('token')
	if (!token) {
		return res.json({
			code: '2004',
			msg: 'token缺失',
			data: null
		})
	}
	console.log(token)
	jwt.verify(token, KEY, (err, data) => {
		console.log(err, data)
		if (err) {
			return res.json({
				code: '2003',
				msg: 'token校验失败',
				data: null
			})
		} else {
			req.user = data
			next()
		}
	})
}